<template>
  <div style="position: relative;">
    <div style="position: absolute;top:200px;left:200px">
      <van-form @submit="onSubmit">
        <van-field
            v-model="from.name"
            name="账号"
            label="账号"
            placeholder="账号"
            :rules="[{ required: true, message: '请填写账号' }]"
        />
        <van-field
            v-model="from.password"
            type="password"
            name="密码"
            label="密码"
            placeholder="密码"
            :rules="[{ required: true, message: '请填写密码' }]"
        />
        <div style="margin: 16px;">
          <van-button round block type="info" native-type="submit">提交</van-button>
        </div>
      </van-form>
    </div>
  </div>
</template>

<script>
import maxios from "@/http/axios";

export default {
name: "login",
  data() {
    return {
      from:{'name':'','password':''}
    };
  },
  methods:{
    onSubmit() {
      maxios('/user/login','post',this.from).then(res=>{
        if(res.code==200){
          this.$toast.success('登陆成功')
          console.log(res.matter)
          localStorage.setItem('user_id',res.matter['id'])
          localStorage.setItem('username',res.matter['name'])
          localStorage.setItem('password',res.matter['password'])
          localStorage.setItem('token',res.token)
          localStorage.setItem('reslist',res.url.join(','))
          this.$router.push('/index')
        }else{
          this.$toast.fail('用户名或密码错误')
        }
      })
    },

  },
  mounted() {

  }
}
</script>

<style scoped>

</style>